package com.cyj.codegen.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.api.R;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cyj.codegen.model.GenDatasourceConf;
import com.cyj.codegen.service.GenDatasourceConfService;
import io.swagger.annotations.Api;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * @Description: 数据源表控制器
 * @BelongsProject: MybatisPlusCodeGenDemoMaven
 * @BelongsPackage: com.cyj.codegen.controller
 * @Author: ChenYongJia
 * @CreateTime: 2021-09-09 11:02
 * @Email: chen87647213@163.com
 * @Version: 1.0
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/dsConfig")
@Api(value = "dsConfig", tags = "数据源表控制器")
public class GenDsConfController {

    private final GenDatasourceConfService datasourceConfService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param datasourceConf 数据源表
     * @return
     */
    @GetMapping("/page")
    public R getSysDatasourceConfPage(Page page, GenDatasourceConf datasourceConf) {
        return R.ok(datasourceConfService.page(page, Wrappers.query(datasourceConf)));
    }

    /**
     * 查询全部数据源
     * @return
     */
    @GetMapping("/list")
    public R list() {
        return R.ok(datasourceConfService.list());
    }

    /**
     * 通过id查询数据源表
     * @param id id
     * @return R
     */
    @GetMapping("/{id}")
    public R getById(@PathVariable("id") Integer id) {
        return R.ok(datasourceConfService.getById(id));
    }

    /**
     * 新增数据源表
     * @param datasourceConf 数据源表
     * @return R
     */
    @PostMapping("/save")
    public R save(@RequestBody GenDatasourceConf datasourceConf) {
        return R.ok(datasourceConfService.saveDsByEnc(datasourceConf));
    }

    /**
     * 修改数据源表
     * @param conf 数据源表
     * @return R
     */
    @PutMapping("/updateById")
    public R updateById(@RequestBody GenDatasourceConf conf) {
        return R.ok(datasourceConfService.updateDsByEnc(conf));
    }

    /**
     * 通过id删除数据源表
     * @param id id
     * @return R
     */
    @DeleteMapping("/{id}")
    public R removeById(@PathVariable Integer id) {
        return R.ok(datasourceConfService.removeByDsId(id));
    }

}
